<template>
  <div>
    <!-- van-tabs:
	   通过v-model绑定当前激活标签对应的索引值，默认情况下启用第一个标签
	   通过animated属性可以开启切换标签内容时的转场动画
	   通过swipeable属性可以开启滑动切换标签页
    -->
    <van-tabs v-model="active" animated swipeable>
      <van-tab v-for="item in channels" :key="item.id" :title="item.name">
        <article-list :item="item"></article-list>  
        </van-tab>
    </van-tabs>
  </div>
</template>
<script>
import ArticleList from './components/article-list.vue'
import { getMyChannels } from '@/api/channel'
export default {
  name: 'Home',
  components: {
    ArticleList
  },
  data () {
    return {
      active: 0,
      channels:[]   //放频道列表的变量
    }
  },
  created () {
    //在created钩子函数中调用该方法
    this.loadChannels()
  },
  methods: {
    //封装一个方法，方法会调接口，拿到频道列表的数据，并且放到变量的身上
   async loadChannels(){
    const res = await getMyChannels()
    this.channels=res.data.channels
   }
  }
}
</script>

<style lang="less" scoped>
/deep/ .van-tabs_wrap{
  position: fixed;
  top: 0;
  z-index: 1;
  width: 100vw;
}
/deep/ .van-tabs {
  .van-tab {
    border-right: 1px solid #edeff3;
    min-width: 200px;
    height: 80px;
    .van-tab__text {
      font-size: 27px;
      color: #777777;
    }
  }

  .van-tab--active .van-tab__text {
    color: #333 !important;
  }
  .van-tabs__line {
    width: 31px !important;
    height: 6px;
    background: rgba(50, 150, 250, 1);
    border-radius: 3px;
    bottom: 8px;
  }
  .van-tabs__nav {
    padding: 0;
  }
}
</style>